﻿@typeparam TModel

@if (Show)
{
    @if (IsDelta)
    {
        <span class="alert alert-warning"><strong>@Property(DbModel)</strong></span>
    }
    else
    {
        <span class="alert alert-success">(same)</span>
    }
}
@code {
    /// <summary>
    /// The <see cref="TModel"/> being edited.
    /// </summary>
    [Parameter]
    public TModel Model { get; set; }

    /// <summary>
    /// The <see cref="TModel"/> in the database.
    /// </summary>
    [Parameter]
    public TModel DbModel { get; set; }

    /// <summary>
    /// Returns the property to inspect.
    /// </summary>
    [Parameter]
    public Func<TModel, IComparable> Property { get; set; }

    /// <summary>
    /// Only show if concurrency conflict exists.
    /// </summary>
    private bool Show => Model != null && DbModel != null;

    /// <summary>
    /// Highlight properties with different values.
    /// </summary>
    private bool IsDelta => !Property(Model).Equals(Property(DbModel));
}
